#!/bin/python

"""
This script iterates over values for epsilon0 and the various times, 
allowing us to check measurements that are stronger/weaker, 
longer/shorter. The basic pattern is to prepare a list of epsilons and 
T's to check, then loop, modifying trajectory_input_file and running 
parallel_job.py to copy/paste everything into a timestamped directory.
"""

import subprocess
import numpy as np
import cPickle as pickle
from utils import gaussian_pulse

#epsilon0_list = np.linspace(0.5,2.0,10)
#meas_t_list = np.linspace(10.,18.,10) 

#epsilon0_list = np.linspace(0.4,0.7,25)
#sigma_list =np.linspace(2.,10.,5)

meas_t_list = np.linspace(10.,18.,10) 
stdev_mul_list = np.linspace(0.1,1.0,10)
h_offset_list = np.linspace(0.1,0.5,10)
h_peak_list = np.linspace(0.1,0.5,10)

""" #constant pulses 
for epsilon0 in epsilon0_list:
    for meas_t in meas_t_list:
        #for sigma in sigma_list:
            with open('trajectory_input_file', 'r') as phil:
                input_dict = pickle.load(phil)
            
            #Here, I'm copying code over from input_prep.py. So dirty.
            input_dict['tmeas_off'] = meas_t
            toff = input_dict['tmeas_off'] - 2.
            #This will only give real results for the
            #decoherence-free case:
            fudge_factor = 1.2 
            input_dict['T'] = fudge_factor * input_dict['tmeas_off']
            input_dict['N'] = int(round(input_dict['T']/input_dict['dt']))
            input_dict['tvec'] = np.linspace(0.,input_dict['T'],input_dict['N'])
            input_dict['epsilon'] = np.array([epsilon0 * float(t <= toff) for t in input_dict['tvec']])                
            with open('trajectory_input_file', 'w') as phil:
                pickle.dump(input_dict, phil)    
            
            subprocess.check_call(['sleep','2'])
            subprocess.call(['python', 'parallel_job.py'])
"""

for stdev_mul in [0.3]: #overridden
    for h_offset in h_offset_list:
        for h_peak in h_peak_list:
            for meas_t in meas_t_list:
                with open('trajectory_input_file', 'r') as phil:
                    input_dict = pickle.load(phil)                
                #Here, I'm copying code over from input_prep.py. So dirty.
                input_dict['tmeas_off'] = meas_t
                toff = input_dict['tmeas_off'] - 2.
                #This will only give real results for the
                #decoherence-free case:
                fudge_factor = 1.2 
                input_dict['T'] = fudge_factor * input_dict['tmeas_off']
                input_dict['N'] = int(round(input_dict['T']/input_dict['dt']))
                input_dict['tvec'] = np.linspace(0.,input_dict['T'],input_dict['N'])
                input_dict['epsilon'] = gaussian_pulse(h_offset, h_peak, stdev_mul*meas_t, input_dict['tvec'])
                input_dict['h_offset'] = h_offset
                input_dict['h_peak'] = h_peak
                input_dict['stdev_mul'] = stdev_mul                    
                with open('trajectory_input_file', 'w') as phil:
                    pickle.dump(input_dict, phil)    
                
                subprocess.check_call(['sleep','2'])
                subprocess.call(['python', 'parallel_job.py'])
